function VehicleFillupsView() {
	var self = Ti.UI.createView({
    	top: 0,
		left: 0,
		width: '100%',
		height: 'auto',
		backgroundColor:'white'
	});
	
	var table = Ti.UI.createTableView({
		data:[]
	});
	
	self.addEventListener('updateFillupsTableEvent', function(e) {
		table.setData(GetVehicleFillupsArray(e.vehicleId, e, self));
	});
	
	table.addEventListener('click', function(e) {
		self.fireEvent('editVehicleFillUpEvent', {
			vehicleId: e.rowData.vehicleId,
			fillupId : e.rowData.fillupId,
			vehicleName: e.rowData.vehicleName
		});
	});
	
	self.add(table);
	
	return self;
}

// TODO:
// This should not be in the view
function GetVehicleFillupsArray(vehicleId) {
	var data = [];
	var VehicleFillupsModel = require('/models/VehicleFillup');
	var vehicleFillups = VehicleFillupsModel.findByVehicleID(vehicleId);
	for(var i=0; i<vehicleFillups.length; i++) {
	
		var vehicleFillup = vehicleFillups[i];
		
		var row = Ti.UI.createTableViewRow();
		row.selectionStyle = Ti.UI.iPhone.TableViewCellSelectionStyle.BLUE;
		row.height = 50;
		row.vehicleId = vehicleId;
		row.fillupId = vehicleFillup.fillupId;
		row.vehicleName = vehicleFillup.vehicleName;
		
		var nozzleImage = Ti.UI.createImageView({
			image:'nozzle.png',
			left:10,
			width:20
		});
		row.add(nozzleImage);
		
		var fillupDate = Ti.UI.createLabel({
			color:'#576996',
			font:{fontSize:20,fontWeight:'bold', fontFamily:'Arial'},
			top :10,
			left : 47,
			height:30,
			width: 200,
			text:String.formatDate(vehicleFillup.fillupDate)
		});
		row.add(fillupDate);
	
		var fillUpUnits = Ti.UI.createLabel({
			color:'#999',
			font:{fontSize:20,fontWeight:'bold', fontFamily:'Arial'},
			top : 10,
			right:47,
			height:30,
			width: 120,
			textAlign: Ti.UI.TEXT_ALIGNMENT_RIGHT,
			text:vehicleFillup.fillupUnits.toFixed(2) + ' L'
		});
		row.add(fillUpUnits);
		
		var editButton = Ti.UI.createButton({
			style:Titanium.UI.iPhone.SystemButtonStyle.BAR,
			right:5
		});
		
		row.add(editButton);
		
		data.push(row);
	}
	
	return data;
}
module.exports = VehicleFillupsView;